package com.becca.cake.model.coupon;

import java.io.Serializable;
import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;

import com.becca.cake.core.exception.ServiceException;
import com.becca.cake.util.StringUtil;

/**
 * 优惠码表
 * @copyright  尊星(上海)信息科技有限公司
 * @author hejinguo
 * @date 2016年4月10日 上午1:11:16
 */
public class CouponModel implements Serializable {
    /**  */
    private static final long  serialVersionUID           = -8138618423343938655L;

    /**自动生成 1：是*/
    public static final String IS_AUTOMATIC_YES           = "1";
    /**手动输入 0：否*/
    public static final String IS_AUTOMATIC_NO            = "0";
    /**是否可用(0:可用)*/
    public static final Byte   IS_ENABLE_YES              = 0;

    /**优惠码使用状态( 1:已使用 )*/
    public static final Byte   COUPON_STATUS_ALREADY_USER = 1;

    /**是否单次使用(0:单次使用)*/
    public static final Byte   COUPON_SINGLE_YES          = 0;

    /**是否单次使用(1:重复使用)*/
    public static final Byte   COUPON_SINGLE_NO           = 1;

    /**优惠码使用状态(0:未使用)*/
    public static final Byte   COUPON_STATUS_NO_USER      = 0;

    /**是否可用(0:可用)*/
    public static final Byte   COUPON_IS_ENABLE_YES       = 0;
    /**是否可用(1:不可用)*/
    public static final Byte   COUPON_IS_ENABLE_NO        = 1;

    /**开始日期不能为空*/
    public static final String COUPON_BEGIN_DATE_NULL     = "开始日期不能为空";
    /**优惠码名称不能为空*/
    public static final String COUPON_CODE_NAME_NULL      = "优惠码名称不能为空";
    /**规则组不能为空*/
    public static final String RULE_GROUP_ID_NULL         = "规则组不能为空";
    /**是否参与其它优惠不能为空*/
    public static final String ENJOY_OTHER_ACTIVITY_NULL  = "是否参与其它优惠不能为空";
    /**是否单次使用不能为空*/
    public static final String IS_SINGLE_USER_NULL        = "是否单次使用不能为空";
    /**优惠码状态不能为空*/
    public static final String COUPON_STATUS_NULL         = "优惠码状态不能为空";
    /**是否可用不能为空*/
    public static final String IS_ENABLE_NULL             = "是否可用不能为空";
    /**优惠码不能为空*/
    public static final String COUPON_CODE_NULL           = "优惠码不能为空";
    /**该优惠码已存在*/
    public static final String COUPON_CODE_EXIST          = "该优惠码已存在";
    /**优惠码ID为空*/
    public static final String COUPON_ID_NULL             = "查询优惠码时ID为空";
    /**优惠码对象为空*/
    public static final String COUPON_NULL                = "优惠码对象为空";

    /**优惠码不存在或已使用*/
    public static final String COUPON_NOT_USERS           = "优惠码不存在或已使用";

    private Integer            id;
    /**促销规则组ID*/
    private Integer            ruleGroupId;
    /**优惠码名称*/
    private String             couponCodeName;
    /**优惠码*/
    private String             couponCode;
    /**优惠券开始时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date               couponBeginDate;
    /**优惠券结束时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date               couponEndDate;
    /**是否参与其它活动(0:不参与 1:参与)*/
    private Byte               enjoyOtherActivtity;
    /**是否单次使用(0:单次使用 1:重复使用)*/
    private Byte               isSingleUser;
    /**优惠码使用状态(0:未使用 1:已使用  2:已停用)*/
    private Byte               couponStatus;
    /**是否可用(0:可用 1:不可用)*/
    private Byte               isEnable;
    /**创建时间*/
    private Date               createdDate;
    /**创建人*/
    private String             createdName;
    /**修改时间*/
    private Date               updatedDate;
    /**修改人*/
    private String             updatedName;
    /**规则组名称*/
    private String             ruleGroupName;
    /**优惠码类型(0:普通码 1:B2B码 2:Online-coupon)*/
    private Byte               couponType;

    /***********************************/
    /**开始号段*/
    private Integer            startId;
    /**结束号段*/
    private Integer            endId;
    /**销售人员*/
    private String             salesName;

    public String getSalesName() {
        return salesName;
    }

    public void setSalesName(String salesName) {
        this.salesName = salesName;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getRuleGroupId() {
        return ruleGroupId;
    }

    public void setRuleGroupId(Integer ruleGroupId) {
        this.ruleGroupId = ruleGroupId;
    }

    public String getRuleGroupName() {
        return ruleGroupName;
    }

    public void setRuleGroupName(String ruleGroupName) {
        this.ruleGroupName = ruleGroupName;
    }

    public String getCouponCodeName() {
        return couponCodeName;
    }

    public void setCouponCodeName(String couponCodeName) {
        this.couponCodeName = couponCodeName;
    }

    public String getCouponCode() {
        return couponCode;
    }

    public void setCouponCode(String couponCode) {
        this.couponCode = couponCode;
    }

    public Date getCouponBeginDate() {
        return couponBeginDate;
    }

    public void setCouponBeginDate(Date couponBeginDate) {
        this.couponBeginDate = couponBeginDate;
    }

    public Date getCouponEndDate() {
        return couponEndDate;
    }

    public void setCouponEndDate(Date couponEndDate) {
        this.couponEndDate = couponEndDate;
    }

    public Byte getEnjoyOtherActivtity() {
        return enjoyOtherActivtity;
    }

    public void setEnjoyOtherActivtity(Byte enjoyOtherActivtity) {
        this.enjoyOtherActivtity = enjoyOtherActivtity;
    }

    public Byte getIsSingleUser() {
        return isSingleUser;
    }

    public void setIsSingleUser(Byte isSingleUser) {
        this.isSingleUser = isSingleUser;
    }

    public Byte getCouponStatus() {
        return couponStatus;
    }

    public void setCouponStatus(Byte couponStatus) {
        this.couponStatus = couponStatus;
    }

    public Byte getIsEnable() {
        return isEnable;
    }

    public void setIsEnable(Byte isEnable) {
        this.isEnable = isEnable;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getCreatedName() {
        return createdName;
    }

    public void setCreatedName(String createdName) {
        this.createdName = createdName;
    }

    public Date getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Date updatedDate) {
        this.updatedDate = updatedDate;
    }

    public String getUpdatedName() {
        return updatedName;
    }

    public void setUpdatedName(String updatedName) {
        this.updatedName = updatedName;
    }

    public Integer getStartId() {
        return startId;
    }

    public Integer getEndId() {
        return endId;
    }

    public void setStartId(Integer startId) {
        this.startId = startId;
    }

    public void setEndId(Integer endId) {
        this.endId = endId;
    }

    public Byte getCouponType() {
        return couponType;
    }

    public void setCouponType(Byte couponType) {
        this.couponType = couponType;
    }

    /**
     * 验证是否为空
     * @param couponModel
     */
    public static void validCouponIsNull(CouponModel couponModel) {
        if (couponModel == null) {
            throw new ServiceException(CouponModel.COUPON_NULL);
        }
        if (couponModel.getCouponBeginDate() == null) {
            throw new ServiceException(CouponModel.COUPON_BEGIN_DATE_NULL);
        }
        if (StringUtil.isEmpty(couponModel.getCouponCodeName())) {
            throw new ServiceException(CouponModel.COUPON_CODE_NAME_NULL);
        }
        if (couponModel.getRuleGroupId() == null) {
            throw new ServiceException(CouponModel.RULE_GROUP_ID_NULL);
        }
        if (couponModel.getEnjoyOtherActivtity() == null) {
            throw new ServiceException(CouponModel.ENJOY_OTHER_ACTIVITY_NULL);
        }
        if (couponModel.getIsSingleUser() == null) {
            throw new ServiceException(CouponModel.IS_SINGLE_USER_NULL);
        }
        if (couponModel.getCouponStatus() == null) {
            throw new ServiceException(CouponModel.COUPON_STATUS_NULL);
        }
        if (couponModel.getIsEnable() == null) {
            throw new ServiceException(CouponModel.IS_ENABLE_NULL);
        }
    }

    /**
     * 校验优惠码ID是否为空
     * @param id
     */
    public static void validCouponIdNull(Integer id) {
        if (id == null) {
            throw new ServiceException(CouponModel.COUPON_ID_NULL);
        }
    }

    @Override
    public String toString() {
        return "CouponModel [id=" + id + ", ruleGroupId=" + ruleGroupId + ", couponCodeName="
               + couponCodeName + ", couponCode=" + couponCode + ", couponBeginDate="
               + couponBeginDate + ", couponEndDate=" + couponEndDate + ", enjoyOtherActivtity="
               + enjoyOtherActivtity + ", isSingleUser=" + isSingleUser + ", couponStatus="
               + couponStatus + ", isEnable=" + isEnable + ", createdDate=" + createdDate
               + ", createdName=" + createdName + ", updatedDate=" + updatedDate + ", updatedName="
               + updatedName + "]";
    }

}
